package com.bt.lms.service.impl;

import com.bt.lms.entity.FamilyMemberInfo;
import com.bt.lms.dao.servise.StuFamilyMemberDao;
import com.bt.lms.dao.servise.impl.StuFamilyMemberDaoImpl;
import com.bt.lms.service.StuFamilyMemberService;

import java.sql.SQLException;

/**
 * 家庭成员信息实现
 */
public class StuFamilyMemberServiceImpl implements StuFamilyMemberService {
    @Override
    public boolean edit(Long id, FamilyMemberInfo familyMemberInfo) throws SQLException {

        StringBuilder familySqlSB = new StringBuilder();
        familySqlSB.append("update family_member_info set")
                .append(" relation = ?,name = ?,birthday = ?,work_unit = ?,job = ?,phone = ?,nation = ?,nationality = ?")
                .append(",health_condition = ?,duty = ?,duty_rank = ?,email = ?,isEmergency_contact = ?")
                .append(" where id = ? and stu_basic_info_id = ?");
        String sql = new String(familySqlSB);

        StuFamilyMemberDao stuFamilyMemberDao = new StuFamilyMemberDaoImpl();
        stuFamilyMemberDao.upData(sql,familyMemberInfo,id);




        return true;
    }

    @Override
    public boolean delete(Long id) throws SQLException {
        String sql = "update family_member_info set deleted = ? where id = ? and stu_basic_info_id = ?";

        StuFamilyMemberDao stuFamilyMemberDao = new StuFamilyMemberDaoImpl();
        stuFamilyMemberDao.delete(sql,id);

        return false;
    }

    @Override
    public boolean add(Long id, FamilyMemberInfo familyMemberInfo) throws SQLException {
        StringBuilder addFamilySqlSB = new StringBuilder();
        addFamilySqlSB.append("insert into family_member_info(")
                .append("relation,name,birthday,work_unit,job,phone,nation,nationality")
                .append(",health_condition,duty,duty_rank,email,isEmergency_contact,stu_basic_info_id)")
                .append(" values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        String sql = new String(addFamilySqlSB);

        StuFamilyMemberDao stuFamilyMemberDao = new StuFamilyMemberDaoImpl();
        stuFamilyMemberDao.insert(sql, familyMemberInfo);


        return true;
    }
}
